const express = require('express')
const auth = require('../middleware/auth')
const router = express.Router()

// 获取能耗数据
router.get('/consumption', auth, (req, res) => {
  try {
    const consumption = {
      today: 1250.5,
      yesterday: 1180.3,
      thisMonth: 35420.8,
      lastMonth: 33890.2,
      trend: 'up',
      percentage: 4.5,
      timestamp: new Date().toISOString()
    }
    
    res.json({
      success: true,
      data: consumption
    })
  } catch (error) {
    console.error('Get energy consumption error:', error)
    res.status(500).json({
      success: false,
      error: '获取能耗数据失败'
    })
  }
})

// 获取能耗统计
router.get('/stats', auth, (req, res) => {
  try {
    const stats = {
      totalConsumption: 125000.5,
      averageDaily: 4166.7,
      peakHour: '14:00',
      efficiency: 85.2,
      timestamp: new Date().toISOString()
    }
    
    res.json({
      success: true,
      data: stats
    })
  } catch (error) {
    console.error('Get energy stats error:', error)
    res.status(500).json({
      success: false,
      error: '获取能耗统计失败'
    })
  }
})

module.exports = router